<%@ page import="com.situ.web.entity.Student" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.situ.web.util.PageInfo" %>
<%@ page import="com.situ.web.entity.Teacher" %>
<%@ page import="java.lang.reflect.Array" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/bootstrap-3.4.1-dist/css/bootstrap.css"/>
</head>
<body>
   <%--${list}--%>
   <a class="btn btn-primary" href="<%=request.getContextPath()%>/student_insert.jsp">添加</a>
   <table class="table table-striped table-bordered table-hover table-condensed">
       <tr>
           <td>ID2</td>
           <td>名字</td>
           <td>年龄</td>
           <td>地址</td>
           <td>删除/修改</td>
       </tr>
       <%
            // request：内置对象（这个对象已经创建好了，名字也起好了就叫request）
            // 在这里面可以写java代码
           PageInfo pageInfo = (PageInfo)request.getAttribute("pageInfo");
           ArrayList<Teacher> list =  pageInfo.getList();
           for (Teacher teacher : list) {
       %>
               <tr>
                   <td><%=teacher.getId()%></td>
                   <td><%=teacher.getName()%></td>
                   <td><%=teacher.getAge()%></td>
                   <td><%=teacher.getAddress()%></td>
                   <td>
                       <a class="btn btn-danger btn-sm" href="javascript:void(0)" onclick="deleteById(<%=teacher.getId()%>)">删除</a>
                       <a class="btn btn-warning btn-sm" href="<%=request.getContextPath()%>/teacher?method=selectById&id=<%=teacher.getId()%>" >编辑</a>
                   </td>
               </tr>
       <%
           }
       %>

   </table>
   <nav aria-label="Page navigation">
       <ul class="pagination">
               <%
                    if (pageInfo.getPageNo() > 1) {
               %>
                        <li>
                            <a href="<%=request.getContextPath()%>/teacher?method=selectByPage&pageNo=<%=pageInfo.getPageNo()-1%>" aria-label="Previous">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </li>
               <%
                    } else {
               %>
                        <li class="disabled">
                            <a  aria-label="Previous">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </li>
               <%
                   }
               %>
           <%
                for(int i = 1; i <= pageInfo.getTotalPage(); i++) {
           %>
                    <li><a href="<%=request.getContextPath()%>/teacher?method=selectByPage&pageNo=<%=i%>"><%=i%></a></li>
           <%
                }
           %>
           <li>
               <a href="#" aria-label="Next">
                   <span aria-hidden="true">&raquo;</span>
               </a>
           </li>
       </ul>
   </nav>


    <script type="text/javascript">
        function deleteById(id) {
            var isDelete = confirm('您确认要删除么？');
            if(isDelete) {
                location.href = '<%=request.getContextPath()%>/teacher?method=deleteById&id=' + id;
            }
        }
    </script>
</body>
</html>
